package com.yc.jpyy.complaint.controller;

import com.alibaba.fastjson.JSON;
import com.common.utils.manydatasource.HandlerDataSource;
import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.base.util.PageBean;
import com.yc.jpyy.complaint.service.ComplaintInfoService;
import com.yc.jpyy.utils.Tools;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import javax.servlet.http.HttpServletRequest;

/**
 * 投诉信息处理
 * date: 2018-07-13
 * by:何创强
 */
@Controller
@RequestMapping(value = "/complaintInfo")
@Scope("prototype")
public class ComplaintInfoController extends BaseController {

    private static Logger logger = LoggerFactory.getLogger(ComplaintInfoController.class);

    @Autowired
    private ComplaintInfoService complaintInfoService;


    /**
     * 新增投诉信息
     * @param complaintInfo 投诉信息内容 json字符串
     * @return
     */
    @RequestMapping(value = "/addComplaintInfo", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String add(HttpServletRequest request) {
        logger.info("新增投诉");
    	//add yangbo 20180910 由于数据量大改为getAttributer 接收请求参数
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        try{
            //设置数据源
            String info = request.getAttribute("info").toString();
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            logger.info("paramsMap = " + paramsMap);
            String dbcode = paramsMap.get("dbcode").toString();
            HandlerDataSource.setDataSource(dbcode);
            complaintInfoService.add(paramsMap);
            logger.info("新增投诉信息成功");
            response.setReturnMsg(1, "操作成功");
        }catch (Exception e){
            e.printStackTrace();
            logger.info(e.getMessage());
            response.setReturnMsg(0,"添加失败");
            response.setReturnException(e.toString());
        }finally {
            HandlerDataSource.clear();
        }
        return response.toJSON();
    }

    
    /**
     * 根据车牌号获取对应的司机下拉列表
     * @param info
     * @return
     */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getDriverByVehicleNo", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json; charset=utf-8")
	public @ResponseBody String getDriverByVehicleNo(HttpServletRequest request) throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		Map<String,Object> resultMap = new HashMap<>();
		try {
			String info = request.getParameter("info");
			Map<String,Object> paramsMap = Tools.JsonToMap(info);
			HandlerDataSource.setDataSource("A1");
			//根据传过来的车牌号确定操作哪个子库
            String dbcode = complaintInfoService.getDbcode(paramsMap);
            //重新设置数据源为子库查询司机列表
            HandlerDataSource.setDataSource(dbcode);
			resultMap = complaintInfoService.getDriverByVehicleNo(paramsMap);
			resultMap.put("pubKey",Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
		} catch (Exception e) {
			logger.info("getDriverByVehicleNo" + e.toString());
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "查询失败");
			if(e.getMessage().trim().equals("车牌号错误")) {
				resultMap.put("returnMsg", "车牌号错误");
            }
		} finally {
			HandlerDataSource.clear();
			return JSON.toJSONString(resultMap);
		}
		
	}
    
    
    /**
     * 新增投诉信息
     * @param complaintInfo 投诉信息内容 json字符串
     * @return
     */
    @RequestMapping(value = "/addComplaintInfoForWx", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String addComplaintInfoForWx(HttpServletRequest request) {
        logger.info("微信新增投诉");
    	
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        try{
            //设置数据源
            String info = request.getParameter("info");
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            HandlerDataSource.setDataSource(paramsMap.get("dbcode").toString());
            //paramsMap.put("becomplainantvehicleno", paramsMap.get("becomplainantvehicleno").toString().replaceAll("冀B.T", "BT"));
            //根据传过来的车牌号确定操作哪个子库
            String dbcode = complaintInfoService.getDbcode(paramsMap);
            //重新设置数据源为子库
            HandlerDataSource.setDataSource(dbcode);
            complaintInfoService.addForWx(paramsMap);
            logger.info("新增投诉信息成功");
            response.setReturnMsg(1, "操作成功");
        }catch (Exception e){
            e.printStackTrace();
            logger.info(e.getMessage());
            response.setReturnMsg(0,"添加失败");
            if(e.getMessage().trim().equals("此用户为黑名单用户")) {
            	response.setReturnMsg(0,"此用户为黑名单用户");
            }
            if(e.getMessage().trim().equals("同一用户同一车辆一天只能投诉一次")) {
            	response.setReturnMsg(0,"同一用户同一车辆一天只能投诉一次");
            }
            if(e.getMessage().trim().equals("车牌号错误")) {
            	response.setReturnMsg(0,"车牌号错误");
            }
            response.setReturnException(e.toString());
        }finally {
            HandlerDataSource.clear();
        }
        return response.toJSON();
    }
    

    /**
     * 批量删除投诉信息
     * @param complaintInfo
     * @return
     */
    @SuppressWarnings("finally")
    @RequestMapping(value = "/delComplaintInfo", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String del(@RequestParam(required = true) String info,HttpServletRequest request) {
        logger.info("删除投诉内容:" + info);
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        try{
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            System.out.println("paramsMap"+paramsMap);
            String ids = paramsMap.get("ids").toString();
            String[] idarray = ids.split(",");
            paramsMap.put("idarray", idarray);
            String dbcode = paramsMap.get("dbcode").toString();
            //设置数据源
            HandlerDataSource.setDataSource(dbcode);
            int ret = complaintInfoService.del(paramsMap);
            if(ret>=1) {
                response.setReturnMsg(1, "删除成功");
                return response.toJSON();
            }
            else{
                response.setReturnMsg(0, "删除失败");
                return response.toJSON();
            }

        } catch (Exception e) {
            logger.error("删除公司异常" + e.toString());
            // 异常信息
            response.setReturnCode(0);
            response.setReturnMsg("操作失败");
            response.setReturnException(e.toString());
            e.printStackTrace();
        }

        finally {
            HandlerDataSource.clear();
            return response.toJSON();
        }
    }

    /**
     * 根据id查找单条记录
     * @param complaintInfo
     * @return
     */
    @SuppressWarnings("finally")
    @RequestMapping(value = "/findById", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String findById(@RequestParam(required = true) String info,HttpServletRequest request){
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        try {
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            String dbcode = paramsMap.get("dbcode").toString();
            //设置数据源
            HandlerDataSource.setDataSource(dbcode);
            Map<String, Object> val = complaintInfoService.findByID(paramsMap);
            if(val == null || val.size() == 0) {
                response.setReturnMsg(1, "无查询数据");
                return response.toJSON();
            }
            else {
                response.setReturnMsg(1, "查询单条数据成功");
                response.setListData(val);
                return response.toJSON();
            }

        } catch (Exception e) {
            logger.info("查询单条数据异常" + e.toString());
            // 异常信息
            response.setReturnCode(0);
            response.setReturnMsg("查询单条数据异常");
        } finally {
            HandlerDataSource.clear();
            return response.toJSON();
        }
    }


    /**
     * 更新投诉内容
     * @param complaintInfo
     * @return
     */
    @SuppressWarnings("finally")
    @RequestMapping(value = "/update", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String update(HttpServletRequest request){
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));

        try{
        	String info = request.getAttribute("info").toString();
            logger.info(info);
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            String dbcode = paramsMap.get("dbcode").toString();
            //设置数据源
            HandlerDataSource.setDataSource(dbcode);
            complaintInfoService.update(paramsMap);
            response.setReturnMsg(1, "操作成功");
            return response.toJSON();

        } catch (Exception e) {
            logger.info("新增公司异常" + e.toString());
            // 异常信息
            response.setReturnCode(0);
            response.setReturnMsg("操作失败");
            response.setReturnException(e.toString());
            e.printStackTrace();
        }

        finally {
            HandlerDataSource.clear();
            return response.toJSON();
        }

    }

    /**
     * 分页查询
     * @param complaintInfo
     * @return
     */
    @SuppressWarnings("finally")
    @RequestMapping(value = "/findPage", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String findPage(@RequestParam(required = false) String info,HttpServletRequest request){
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        logger.info("complaintInfo="+info);
        try {
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            logger.info("paramsMap = " + paramsMap);
             String dbcode = paramsMap.get("dbcode").toString();
            //设置数据源
            HandlerDataSource.setDataSource(dbcode);
            // add yangbo 20180819 新增查询条件
            /*if(Tools.isNotEmpty(paramsMap.get("complainantstate"))){
                String complainantstate = paramsMap.get("complainantstate").toString();
                String[] complainantstateArray = complainantstate.split(",");
                paramsMap.put("complainantstateArray", complainantstateArray);
            }*/
            PageBean pageBean = complaintInfoService.findPage(paramsMap);
            response.setReturnMsg(1, "操作成功");
            response.setTotalCount(pageBean.getAllRow());
            response.setTotalPage(pageBean.getTotalPage());
            response.setListData(pageBean.getList());
            return response.toJSON();

        } catch (Exception e) {
            e.printStackTrace();
            logger.error("findCompany" + e.toString());
            response.setReturnCode(1);
            response.setReturnMsg("查询失败");
            response.setReturnException(e.toString());
        } finally {
            HandlerDataSource.clear();
            return response.toJSON();
        }
    }

    
    
    /**
     * 分页查询（打印）
     * @param complaintInfo
     * @return
     */
    @SuppressWarnings("finally")
    @RequestMapping(value = "/findPagePrint", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String findPagePrint(@RequestParam(required = false) String info,HttpServletRequest request){
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        logger.info("complaintInfo="+info);
        try {
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            logger.info("paramsMap = " + paramsMap);
             String dbcode = paramsMap.get("dbcode").toString();
            //设置数据源
            HandlerDataSource.setDataSource(dbcode);
            PageBean pageBean = complaintInfoService.findPagePrint(paramsMap);
            response.setReturnMsg(1, "操作成功");
            response.setTotalCount(pageBean.getAllRow());
            response.setTotalPage(pageBean.getTotalPage());
            response.setListData(pageBean.getList());
            return response.toJSON();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("findCompany" + e.toString());
            response.setReturnCode(1);
            response.setReturnMsg("查询失败");
            response.setReturnException(e.toString());
        } finally {
            HandlerDataSource.clear();
            return response.toJSON();
        }
    }

    /**
     * 获取所有车辆集合
     * @param info
     * @return
     */
    @RequestMapping(value = "/getVehicleAll", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String getVehicleAll(String info,HttpServletRequest request){
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        logger.info("info=",info);
        try{
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            HandlerDataSource.setDataSource(paramsMap.get("dbcode").toString());

            List list = this.complaintInfoService.getVehicleAll(paramsMap);
            response.setListData(list);
            response.setReturnMsg(1,"获取成功");
        }catch (Exception e){
            e.printStackTrace();
            response.setReturnException(e.getMessage());
            response.setReturnMsg(0,"获取失败");
        }finally {
            HandlerDataSource.clear();
        }
        return response.toJSON();
    }

    /**
     * 根据车牌号获取车辆信息
     * @param info
     * @return
     */
    @RequestMapping(value = "/getVehicleByVehicleNo", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String getVehicleByVehicleNo(String info,HttpServletRequest request){
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        logger.info("info=",info);
        try{
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            HandlerDataSource.setDataSource(paramsMap.get("dbcode").toString());
            List list = this.complaintInfoService.getVehicleByVehicleNo(paramsMap);
            response.setListData(list);
            response.setReturnMsg(1,"获取成功");
        }catch (Exception e){
            e.printStackTrace();
            response.setReturnException(e.getMessage());
            response.setReturnMsg(0,"获取失败");
        }finally {
            HandlerDataSource.clear();
        }
        return response.toJSON();
    }

    /**
     * 投诉中心处理投诉信息
     * @param info
     * @return
     */
    @RequestMapping(value = "/complaintHandleByCentent", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String complaintHandleByCentent(HttpServletRequest request){
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        try{
        	String info = request.getAttribute("info").toString();
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            HandlerDataSource.setDataSource(paramsMap.get("dbcode").toString());
            //int state = this.complaintInfoService.complaintHandleByCentent(id,complaintCenterRequirements,complaintCenterReply,new Date());
            this.complaintInfoService.update(paramsMap);
            response.setReturnMsg(1,"处理成功");
        }catch (Exception e){
            e.printStackTrace();
            response.setReturnException(e.getMessage());
            response.setReturnMsg(0,"处理失败");
        }finally {
            HandlerDataSource.clear();
        }
        return response.toJSON();
    }

    /**
     * 投诉转办[更新IsDistribute状态]
     * @param info
     * @return
     */
    @RequestMapping(value = "/complainDistribution", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String complainDistribution(String info,HttpServletRequest request){
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        logger.info("info=",info);
        try{
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            HandlerDataSource.setDataSource(paramsMap.get("dbcode").toString());
            this.complaintInfoService.update(paramsMap);
            response.setReturnMsg(1,"处理成功");
        }catch (Exception e){
            e.printStackTrace();
            response.setReturnException(e.getMessage());
            response.setReturnMsg(0,"处理失败");
        }finally {
            HandlerDataSource.clear();
        }
        return response.toJSON();
    }

    /**
     * 获取公司需要处理的投诉信息【IsDistribute状态=1】
     * @param info
     * @return
     */
    @RequestMapping(value = "/getCompanyComplaint", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String getCompanyComplaint(String info,HttpServletRequest request){
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        logger.info("info=",info);
        try{
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            HandlerDataSource.setDataSource(paramsMap.get("dbcode").toString());
            List list = this.complaintInfoService.getCompanyComplaint(paramsMap);
            response.setListData(list);
            response.setReturnMsg(1,"获取成功");
        }catch (Exception e){
            e.printStackTrace();
            response.setReturnException(e.getMessage());
            response.setReturnMsg(0,"获取失败");
        }finally {
            HandlerDataSource.clear();
        }
        return response.toJSON();
    }

    /**
     * 公司处理投诉信息
     * @param info
     * @return
     */
    @RequestMapping(value = "/complaintHandleByCanpany", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String complaintHandleByCanpany(String info,HttpServletRequest request){
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        logger.info("info=",info);
        try{
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            HandlerDataSource.setDataSource(paramsMap.get("dbcode").toString());
//            int state = this.complaintInfoService.complaintHandleByCanpany(paramsMap);
            this.complaintInfoService.update(paramsMap);
            response.setReturnMsg(1,"处理成功");
        }catch (Exception e){
            e.printStackTrace();
            response.setReturnException(e.getMessage());
            response.setReturnMsg(0,"处理失败");
        }finally {
            HandlerDataSource.clear();
        }
        return response.toJSON();
    }

    /**
     * 批量更改是否催办
     * @param request 是否催办 json字符串
     * @return
     */
    @RequestMapping(value = "/updateIsUrge", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String updateIsUrge(HttpServletRequest request) {
        RestResponse response = new RestResponse(Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
        try{
            //设置数据源
            String Info = request.getParameter("info");
            Map<String,Object> paramsMap = Tools.JsonToMap(Info);
            String dbcode = paramsMap.get("dbcode").toString();
            HandlerDataSource.setDataSource(dbcode);
            paramsMap.put("id",paramsMap.get("ids").toString().split(","));
            int count = complaintInfoService.updateIsUrge(paramsMap);
            response.setListData(count);
            response.setReturnMsg(1, "操作成功");
        }catch (Exception e){
            e.printStackTrace();
            logger.info(e.getMessage());
            response.setReturnMsg(0,"修改失败");
            response.setReturnException(e.toString());
        }finally {
            HandlerDataSource.clear();
        }
        return response.toJSON();
    }

    /**
     * 根据车牌号与车架号 获取投诉信息
     * @param info
     * @return
     */
    @RequestMapping(value = "/wx/getComplaintsByVehicleNo", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String getComplaintsByVehicleNo(String info){
        Map<String,Object> resp = new HashMap<>();
        logger.info("info=",info);
        try{
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            String dbcode = paramsMap.get("dbcode").toString();
            HandlerDataSource.setDataSource(dbcode);
            if(this.complaintInfoService.isVehicleExists(paramsMap)) {
                PageBean pageBean = complaintInfoService.getComplaintByVehicleNo(paramsMap);
                resp.put("returnCode",1);
                resp.put("returnMsg","操作成功");
                resp.put("TotalCount",pageBean.getAllRow());
                resp.put("TotalPage",pageBean.getTotalPage());
                resp.put("pageNum",pageBean.getCurrentPage());
                resp.put("ListData",pageBean.getList());
            }else {
                resp.put("returnCode",0);
                resp.put("returnMsg","车牌号或车架号错误");
            }
        }catch (Exception e){
            e.printStackTrace();
            resp.put("returnCode",0);
            resp.put("returnMsg","获取失败");
            resp.put("returnException",e.getMessage());
        }finally {
            HandlerDataSource.clear();
        }
        return JSON.toJSONString(resp);
    }



    /**
     * 根据身份证号查询车辆信息
     * @param info
     * @return
     */
    @RequestMapping(value = "/wx/getVehiclesByIdNumber", method = { RequestMethod.GET,
            RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String getVehiclesByIdNumber(String info){
        Map<String,Object> resp = new HashMap<>();
        logger.info("info=",info);
        try{
            Map<String,Object> paramsMap = Tools.JsonToMap(info);
            HandlerDataSource.setDataSource("A1");
            PageBean pageBean = complaintInfoService.getVehiclesByIdNumber(paramsMap);
            resp.put("returnCode",1);
            resp.put("returnMsg","操作成功");
            resp.put("TotalCount",pageBean.getAllRow());
            resp.put("TotalPage",pageBean.getTotalPage());
            resp.put("pageNum",pageBean.getCurrentPage());
            resp.put("ListData",pageBean.getList());

        }catch (Exception e){
            e.printStackTrace();
            resp.put("returnCode",0);
            resp.put("returnMsg","获取失败");
            resp.put("returnException",e.getMessage());
        }finally {
            HandlerDataSource.clear();
        }
        return JSON.toJSONString(resp);
    }

    /**
     * 获取Openid，vehicleID，VehicleNo
     * @param info
     * @return
     */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getVehicleOpenid", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json; charset=utf-8")
	public @ResponseBody String getVehicleOpenid(HttpServletRequest request) throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		Map<String,Object> resultMap = new HashMap<>();
		try {
			String info = request.getParameter("info");
			Map<String,Object> paramsMap = Tools.JsonToMap(info);
			String dbcode = paramsMap.get("dbcode").toString();
			HandlerDataSource.setDataSource(dbcode);
			resultMap = complaintInfoService.getVehicleOpenid(paramsMap);
			resultMap.put("pubKey",Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
		} catch (Exception e) {
			logger.info("getVehicleOpenid" + e.toString());
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "获取失败");
		} finally {
			HandlerDataSource.clear();
			return JSON.toJSONString(resultMap);
		}
		
	}
	
	  /**
     * 锁定车辆
     * @param info
     * @return
     */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/updateComplaintTransfer", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json; charset=utf-8")
	public @ResponseBody String updateComplaintTransfer(HttpServletRequest request) throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		Map<String,Object> resultMap = new HashMap<>();
		try {
			String info = request.getParameter("info");
			Map<String,Object> paramsMap = Tools.JsonToMap(info);
			String dbcode = paramsMap.get("dbcode").toString();
			HandlerDataSource.setDataSource(dbcode);
			resultMap = complaintInfoService.updateComplaintTransfer(paramsMap);
			resultMap.put("pubKey",Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
		} catch (Exception e) {
			logger.info("updateComplaintTransfer" + e.toString());
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "锁定失败");
		} finally {
			HandlerDataSource.clear();
			return JSON.toJSONString(resultMap);
		}
		
	}
	
	 /**
     * 查询是否绑定
     * @param info
     * @return
     */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/checkIsBind", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json; charset=utf-8")
	public @ResponseBody String checkIsBind(HttpServletRequest request) throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		Map<String,Object> resultMap = new HashMap<>();
		try {
			String info = request.getParameter("info");
			Map<String,Object> paramsMap = Tools.JsonToMap(info);
			String dbcode = paramsMap.get("dbcode").toString();
			HandlerDataSource.setDataSource(dbcode);
			resultMap = complaintInfoService.checkIsBind(paramsMap);
			resultMap.put("pubKey",Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
		} catch (Exception e) {
			logger.info("checkIsBind" + e.toString());
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "获取失败");
		} finally {
			HandlerDataSource.clear();
			return JSON.toJSONString(resultMap);
		}
		
	}
	
	 /**
     * 根据电话号码分页获取投诉信息
     * @param info
     * @return
     */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getComplaintInfoByPage", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json; charset=utf-8")
	public @ResponseBody String getComplaintInfoByPage(HttpServletRequest request) throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		Map<String,Object> resultMap = new HashMap<>();
		try {
			String info = request.getParameter("info");
			Map<String,Object> paramsMap = Tools.JsonToMap(info);
			String dbcode = paramsMap.get("dbcode").toString();
			HandlerDataSource.setDataSource(dbcode);
			resultMap = complaintInfoService.getComplaintInfoByPage(paramsMap);
			resultMap.put("pubKey",Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
		} catch (Exception e) {
			logger.info("getComplaintInfoByPage" + e.toString());
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "获取失败");
		} finally {
			HandlerDataSource.clear();
			return JSON.toJSONString(resultMap);
		}
		
	}
	
	
	
	/**
     * 根据主键ID修改投诉表中的附件地址
     * @param info
     * @return
     */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/updateComplaintAnnexByID", method = { RequestMethod.GET,
			RequestMethod.POST }, produces = "application/json; charset=utf-8")
	public @ResponseBody String updateComplaintAnnexByID(HttpServletRequest request) throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		Map<String,Object> resultMap = new HashMap<>();
		try {
			String info = request.getParameter("info");
			Map<String,Object> paramsMap = Tools.JsonToMap(info);
			String dbcode = paramsMap.get("dbcode").toString();
			HandlerDataSource.setDataSource(dbcode);
			resultMap = complaintInfoService.updateComplaintAnnexByID(paramsMap);
			resultMap.put("pubKey",Optional.ofNullable(request.getAttribute("pubKey")).orElse(""));
		} catch (Exception e) {
			logger.info("updateComplaintAnnexByID" + e.toString());
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "修改失败");
		} finally {
			HandlerDataSource.clear();
			return JSON.toJSONString(resultMap);
		}
		
	}
}
